package com.qf.service.impl;

import com.qf.dao.UserDao;
import com.qf.dao.impl.UserDaoImpl;
import com.qf.domain.User;
import com.qf.service.UserService;

import java.util.List;

/**
 * @author YDW
 * projectName:shopping
 * time:2022/4/18 17:27
 * description:用户业务层接口实现类
 */
public class UserServiceImpl implements UserService {
    UserDao userDao=new UserDaoImpl();
    @Override
    public boolean checkUsername(String username) {
        //查询数据库是否存在此用户名
        //发起查询：根据用户名查询用户个数
        Long count=userDao.selectByUsername(username);
        return count>0;
    }

    @Override
    public boolean register(String username, String password, String email, String gender) {
        User user=new User(username,password,email,gender,1,1,"");
        int count=userDao.insert(user);
        return count==1;
    }

    @Override
    public User login(String username, String password) {
        User user=userDao.selectByUsernameAndPassword(username,password);
        return user;
    }

    @Override
    public List<User> findUserByUsername(String username) {
        return userDao.findUserByUsername(username);
    }
}
